<template>
  <div class="container">
    <el-dialog title="预览文章" :visible.sync="dialogVisible" width="800px">
      <div class="title">
        <h2>{{ BrowseList.title }}</h2>
        <div>
          <span>{{ BrowseList.createTime | parseTimeByString }}</span>
          <span>{{ BrowseList.username }}</span>
          <span class="el-icon-view"></span>
          <span>{{ BrowseList.visits }}</span>
        </div>
      </div>
      <div class="content" v-html="BrowseList.articleBody"></div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'ArticlesPreview',
  props: {
    data: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      dialogVisible: false,
      BrowseList: []
    }
  },
  methods: {
    open() {
      this.dialogVisible = true
      if (this.data.id) {
        this.BrowseList = this.data
      } else {
        this.BrowseList = {}
      }
      // 清除校验效果
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
    }
  }
}
</script>

<style scoped lang="scss">
.title h2 {
  margin: 0;
}
.title span {
  margin-left: 10px;
  margin-top: 10px;
}
.content {
  background: rgb(245, 245, 245);
  padding: 10px;
}
</style>
